/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyThread;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextArea;

/**
 *
 * @author QuangHau
 */
public class Watting extends Thread {

    private JTextArea textArea;
    boolean stopThread = false;
    String value;

    public Watting(JTextArea _textArea) {
        textArea = _textArea;
    }

    public void run() {
        String str = textArea.getText();
        int len = textArea.getText().length() + 10;
        while (true) {
            if (stopThread) {
                break;
            }
            if (textArea.getText().length() == len) {
                textArea.setText(str);
            } else {
                textArea.setText(textArea.getText() + ".");
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                Logger.getLogger(Watting.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        if(value.equals(": Cancel"))
        {
              textArea.setText(str + value + ".\nStopped!!!\n");
        }
        else
        {
            textArea.setText(str + value + ".\n");
        }
        textArea.setCaretPosition(textArea.getDocument().getLength());
    }

    public void stopWatting(String _value) {
        stopThread = true;
        value = _value;
    }
}
